package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.OrderList;
import com.qf.pojo.Sys_order;
import com.qf.pojo.Sys_user;
import com.qf.service.*;

import com.qf.vo.ActionResult;
import com.qf.vo.BaseResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单信息管理
 */
@RestController
public class Sys_orderController {
    @Autowired
    private Sys_carService sys_carService;
    @Autowired
    private Sys_cityService sys_cityService;
    @Qualifier("sys_OrderService")
    @Autowired
    private Sys_OrderService sys_orderService;
    @Autowired
    private OrderListService orderListService;
    @Autowired
    private Sys_userService userService;
    @RequestMapping(value = "/getcarAndCiry")
public ActionResult findcarAndCity(Integer uid,Integer getid,Integer backid,Integer cid){
    ArrayList<Object> list=new ArrayList<>();
        Sys_user user = userService.findById(uid);
        list.add(sys_cityService.select(getid));
       list.add(sys_cityService.select(backid));
       list.add(sys_carService.findCarBycId(cid));
        list.add(user);
        ActionResult result=new ActionResult(200,null,list);
        return result;
    }
    @RequestMapping(value = "/addOrder")
    public ActionResult addOrder(Integer uid,Double oprice,Integer getid,Integer backid,Integer cid){
        ArrayList<Object> list = new ArrayList<>();
        Sys_order o = new Sys_order();
        o.setCid(cid);
        o.setGetid(getid);
        o.setBackid(backid);
        o.setUid(uid);
        o.setOprice(oprice);
        Sys_order sys_order = sys_orderService.insertOrder(o);
        list.add(sys_order);
        list.add(uid);
        ActionResult result = new ActionResult(200, "提交成功", list);
//        System.out.println(result);
        return result;
    }


    @RequestMapping(value = "/getAllOrder",method = RequestMethod.GET)
    public BaseResult getAllOrder(Integer page, Integer limit, @Param("id")Integer uid, @Param("tel") String tel){
        List<OrderList> orders = orderListService.findAllOrder(page,limit,uid,tel);
        PageInfo<OrderList> info = new PageInfo<>(orders);
        BaseResult actionResult = new BaseResult(200, null, orders,info.getTotal());
        System.out.println(actionResult);
        return actionResult;
    }
    @RequestMapping(value = "/getAllOrder2",method = RequestMethod.GET)
    public ActionResult getAllOrder(@Param("id")Integer uid,@Param("tel") String tel){
        List<OrderList> allOrderNoPage = orderListService.findAAOrderNoPage(uid, tel);
        ActionResult result = new ActionResult(200, null, allOrderNoPage);
        return result;
    }
    @RequestMapping(value = "/deleteOrder",method = RequestMethod.DELETE)
    public ActionResult deleteOrder(Integer id){
        orderListService.deleteOrder(id);
        return  new ActionResult(200, null, null);
    }


}
